﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Web;

namespace SmartSpace.News.UI.Parts
{
    public partial class AssetCategoryList : SsPart
    {
        public AssetCategoryList()
            : base(new Guid("{79C75F08-EF1E-460E-85BD-F9B5D4342655}"))
        {

        }

        protected override void OnLoad(EventArgs e)
        {
            if (!IsPostBack)
            {
                BindCategoryList();
            }
        }

        private void BindCategoryList()
        {
            AssetService service = new AssetService();
            _ctlList.DataSource = service.GetCategories().Data;
            _ctlList.DataBind();
        }

        protected void _ctlList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            Guid categoryID = new Guid(e.CommandArgument.ToString());
            if (e.CommandName == "Delete")
            {
                AssetService service = new AssetService();
                service.DeleteCategory(categoryID);
            }
        }
    }
}